package site.brood.mall.util;


import cn.hutool.extra.spring.SpringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import site.brood.mall.pms.brand.PmsBrandServiceImpl;
import site.brood.mall.util.redis.RedisService;
import site.brood.mall.mapper.PmsBrandMapper;
import site.brood.mall.pms.brand.PmsBrandService;

/**
 * SpringBean列表
 * 项目中工具Bean在获取
 * 1)mapper
 * 2)service
 */
@Component
@Slf4j
public class ToolKit implements CommandLineRunner {

    //------------------------------Mapper------------------------------------
    public static PmsBrandMapper pmsBrandMapper;

    //------------------------------Service------------------------------------
    public static PmsBrandService pmsBrandService;
    public static RedisService redisService;

    @Override
    public void run(String... args) throws Exception {
        //初始化mapperBean
        initMapper();
        //初始化serviceBean
        initService();
        log.info("业务Bean注入完成。。。");
    }

    /**
     * 初始化Mapper
     */
    public void initMapper() {
        ToolKit.pmsBrandMapper = SpringUtil.getBean(PmsBrandMapper.class);
    }

    /**
     * 初始化Service
     */
    public void initService() {
        ToolKit.pmsBrandService = SpringUtil.getBean(PmsBrandServiceImpl.class);
        ToolKit.redisService = SpringUtil.getBean(RedisService.class);
    }
}
